<?php
class AccountAction extends CommonAction {
	
	/**
	 * 删除
	 * @param unknown_type $id
	 */
	public function del($id) {
		$result = false;
// 		$account =D( "Account" );
		//$result = $Student->Where('id='.$id )->delete();
// 		$result = $account->delete($id);
		$result = $this->deleteById($id);
		if ($result == false) {
			echo json_encode (array(
					'errorMsg' => '删除出错！' 
			));
		} else {
			echo json_encode (array(
					'success' => true 
			));
		}
	}
	
	/**
	 * 修改
	 * @param 
	 */
	public function save() {
		$result = false;
		$id = $_GET["id"];
		$account = M ("Account");
		if($account->create()) {
			$result = $account->where('id='.$_REQUEST['id'] )->save();
			if($result) {
				echo json_encode (array('success'=>true));
			}else{
				echo json_encode (array('errorMsg'=>'修改出错！'));
			}
		}else{
			echo json_encode (array('errorMsg'=>$account->getError()));
		}
	}
	
	/**
	 * 新增
	 */
	public function add() {
		$xqid =  $_POST["ZM_XQ"];
		if(empty($xqid)){
			if(isset($_SESSION['xqid'])) {
				$xqid =$_SESSION['xqid'];
			}
		}

// 		$object = array();
		$result = false;
// 		$account = M("Account");
		$account= D('Account');
		$_POST["ZM_LS"] = $account->getAccountLSBH($xqid,date("Ymd"));
		$_POST["ZM_CLRID"] = $_SESSION['loginUserId'];
		$_POST["ZM_CLR"] = $_SESSION['loginUserName'];
		$_POST["ZM_CLSJ"] = date("Y-m-d H:i:s");
		if($account->create()) {
// 			$object["ZM_LS"] = $accountMode->getAccountLSBH($xqid,date("Ymd"));
// 			data($object);
			$result = $account->add();
			if($result) {
				echo json_encode (array('success'=>true));
			}else{
				echo json_encode (array('errorMsg'=>'添加出错！'));
			}
		}else{
			echo json_encode (array('errorMsg'=>$account->getError()));
			//$this->error($course->getError());
		}

	}
	
	/**
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read()
	 */
	public function read() {
		$map =  array ();
		
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$account = M ("Account");
		$total = $account->where($map)->count (); // 计算总数	

		$accountList = $account->where($map)->limit (($pagenum - 1) * $rowsnum . ',' . $rowsnum )->order ( 'id asc' )->select ();
		$resultJson = json_encode($accountList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中		
		echo $json;
	}
	
	public function getDisplayList(){
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
		
		$xqid =  $_POST["XQ"];
		if(empty($xqid)){
			$xqid =  $_SESSION['XqFilterString'];
		}else{
			$xqid = "'" . $xqid ."'";
		}
		
		$lb = $_POST['LB'];
		$CZLX = $_POST['CZLX'];
		$CLR = $_POST['CLR'];
		$JE_GREATER = $_POST['JE_GREATER'];
		$JE_LESS = $_POST['JE_LESS'];
		$CJSJ_START = $_POST['CJSJ_START'];
		$CJSJ_END = $_POST['CJSJ_END'];
		
		
		$offset = ($page-1)*$rows;
		$account = D ( "Account" );
		$result = $account->getModeDisplayList($xqid,$lb,$CZLX,$CLR,$JE_GREATER,$JE_LESS,$CJSJ_START,$CJSJ_END,$offset,$rows);
		echo json_encode($result);
	}

}
?>
